﻿Imports System.Data.OleDb


Public Class addPicture
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click

        Dim myGUID As New System.Guid
        myGUID = Guid.NewGuid()
        Dim newFileName = myGUID.ToString() + ".jpg"

        If f_picture.HasFile Then
            Dim picLocationOnServerHardDisk = Request.MapPath("pictures") & "/" & newFileName
            f_picture.SaveAs(picLocationOnServerHardDisk)

        End If

        Dim oledbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("lensPicConnectionString").ConnectionString)
        Dim sql As String = "INSERT INTO lenspic(PictureTitle,Location,Description,NameofUploader,CameraUsed,Picture) VALUES (@f1,@f2,@f3,@f4,@f5,@f6)"
        Dim cmd As OleDbCommand = New OleDbCommand(sql, oledbConn)
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@f1", tb_pictureTitle.Text)
        cmd.Parameters.AddWithValue("@f2", tb_location.Text)
        cmd.Parameters.AddWithValue("@f3", tb_description.Text)
        cmd.Parameters.AddWithValue("@f4", tb_nameOfUploader.Text)
        cmd.Parameters.AddWithValue("@f5", tb_cameraUsed.Text)
        cmd.Parameters.AddWithValue("@f6", "picture/" & newFileName)
        oledbConn.Open()
        cmd.ExecuteNonQuery()
        Response.Redirect("confirmation.aspx")
    End Sub
End Class